# 自定义数组类，实现插入数据逻辑
class MyArray:
    def __init__(self, capacity):
        self.array = [None] * capacity
        self.size = 0

    def insert(self, index, element):
        '''

        :param index:
        :param element:
        :return:
        '''
        if index < 0 or index > self.size:
            raise Exception("超出数组允许范围")
        self.resize()
        # 将插入位置后边数据依次后移
        for i in range(self.size - 1, -1, -1):
            self.array[i + 1] = self.array[i]
        self.array[index] = element
        self.size += 1

    def remove(self, index):
        '''
        删除元素
        :param index: 删除元素位置
        '''
        if index < 0 or index > self.size:
            raise Exception("超出数组实际元素范围")
        for i in range(index, self.size):
            self.array[i] = self.array[i + 1]
        self.size -= 1

    def output(self):
        for i in range(self.size):
            print(self.array[i], end=' ')

    def resize(self):
        if self.size >= len(self.array):
            array_new = [None] * len(self.array) * 2
            for i in range(self.size):
                array_new[i] = self.array[i]
            self.array = array_new


if __name__ == '__main__':
    array = MyArray(5)
    array.insert(0, 1)
    array.insert(1, 2)
    array.insert(0, 3)
    array.insert(0, 4)
    array.insert(0, 10)
    array.insert(0, 12)
    array.insert(0, 13)
    array.output()
    print()
    array.remove(3)
    array.output()
